<?php
/*------------------------------------------------------------------------
 * User.php 
 *
 * 用户控制器
 * 	
 * Created on 2017-01-05
 *
 * Author: hwc123 <hwc123@139.com>
 * 
 * Copyright (c) 2017 All rights reserved.
 * ------------------------------------------------------------------------
 */

namespace app\index\controller;

class User extends UserBase{

	public function index(){

		
	}

	public function set_fav(){
		$this->user_id();
		$user_id = $this->_get('user_id', '对不起，您的操作有误！');
		if($user_id == $this->_user_id){
			$this->error('不能关注自己！');
		}

		$reid = model('User')->set_fav('UserData', 'by_fav_user_num', 'user_id', $this->_user_id, $user_id, 'fav_user');
		if($reid > 0){
			$data['node_id'] = 'user-id-' . $user_id;
			$data['node_data']['fav_num'] = model('User')->_total_fav_num;
			// 更新收藏用户数量
			model('UserData')->update_user_data($this->_user_id, 'fav_user_num', $reid == 1 ? 1 : -1);
			$this->success($reid == 1 ? '关注成功！' : '取消关注！', '', $data);
		}else{
			$this->error(model('User')->tips_info, '');
		}
	}
	//退出登录
	public function logout(){
		model('User')->clear_login_session();
		$this->redirect(url('/'));
	}

}